
#include "zen_game_matrix.h"
#include "zen_log.h"
#include "zen_game_activity.h"

void Zen::Game::Transform2D_::SetMatrixDirty(bool dirty)
{
	mIsTransformDirty = dirty;
}

Zen::Mat4 Zen::Game::Transform2D_::Transform()
{
	auto m = Mat4MakeIdentity();

	float cos = cosf(mRotation);
	float sin = sinf(mRotation);
	float x = mSize.x * mScale.x;
	float y = mSize.y * mScale.y;

	m[0] = cos * mSkew.x * x;
	m[1] = sin * mSkew.y * x;
	m[4] = -sin * mSkew.x * y;
	m[5] = cos * mSkew.y * y;
	m[12] = mPosition.x - m[0] * mAnchor.x - m[4] * mAnchor.y;
	m[13] = mPosition.y - m[1] * mAnchor.x - m[5] * mAnchor.y;

	return m;
}

void Zen::Game::Transform3D_::SetMatrixDirty(bool dirty)
{
	mIsTransformDirty = dirty;
}

Zen::Mat4 Zen::Game::Transform3D_::Transform()
{
	auto m1 = Mat4MakeTranslation(mPosition);
	auto m2 = Mat4MakeRotation(mRotationAngle, mRotationAxis);
	auto m3 = Mat4MakeScale(mScale * mSize);
	return (m1 & m2 & m3);
}
